import axios from 'axios'

// create an axios instance
const service = axios.create({
  baseURL: 'http://127.0.0.1:8000/', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    config.headers.Authorization = window.sessionStorage.getItem('token')

    return config
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
    const { data: res } =  response
    if(res.code === 10101 || res.code === 10102) {
      window.sessionStorage.setItem('wuhu', 'ddxsx')
    }
    return response
  }
)

export default service
